package com.iflytek.aidemo.util;

/**
 * 网络配置类
 */
public class NetworkConfig {
    
    // 开发环境API地址
    public static final String DEV_BASE_URL = "http://10.0.2.2:8080/api";
    
    // 测试环境API地址
    public static final String TEST_BASE_URL = "http://test-api.example.com/api";
    
    // 生产环境API地址
    public static final String PROD_BASE_URL = "http://api.example.com/api";
    
    // 当前使用的API地址 - 请根据实际环境修改
    public static final String BASE_URL = DEV_BASE_URL;
    
    // 网络请求超时时间（毫秒）
    public static final int CONNECT_TIMEOUT = 10000; // 10秒
    public static final int READ_TIMEOUT = 15000; // 15秒
    
    // API端点
    public static final String LOGIN_ENDPOINT = "/users/login";
    public static final String REGISTER_ENDPOINT = "/users/register";
    public static final String CHECK_USERNAME_ENDPOINT = "/auth/check-username";
    public static final String CHECK_EMAIL_ENDPOINT = "/auth/check-email";
    public static final String LOGOUT_ENDPOINT = "/auth/logout";
    public static final String REFRESH_TOKEN_ENDPOINT = "/auth/refresh";

    public static final String ANSWER_RECORDS_ENDPOINT = "/answer-records";

    public static final String WRONNG_LIST_ENDPOINT = "/wrong-questions/student";

    public static final String UPLOAD_WRONG_ENDPOINT="/wrong-questions";
    // 提交已完成错题（用于删除/标记完成）
    public static final String COMPLETE_WRONG_ENDPOINT = "/wrong-questions/deleteByStudentId";

    // 教师端 成绩查询相关端点
    public static final String TEACHER_ENDPOINT = "/teachers/user/";
    public static final String TEACHER_CLASSES_ENDPOINT = "/classes/"; // + "/classes+ {teacherId} "
    public static final String CLASS_OVERVIEW_ENDPOINT = "/answer-records/getRecordByClassIdAndTime";   // + {classId} + "/overview" + ?date=yyyy-MM-dd
    public static final String STUDENT_SCORE_DETAIL_ENDPOINT = "/answer-records/getRecordByStudentIdAndTime"; // + {studentId} + "/scores" + ?date=yyyy-MM-dd
    
    /**
     * 获取完整的API URL
     */
    public static String getApiUrl(String endpoint) {
        return BASE_URL + endpoint;
    }
    
    /**
     * 获取登录API URL
     */
    public static String getLoginUrl() {
        return getApiUrl(LOGIN_ENDPOINT);
    }
    
    /**
     * 获取注册API URL
     */
    public static String getRegisterUrl() {
        return getApiUrl(REGISTER_ENDPOINT);
    }
    
    /**
     * 获取检查用户名API URL
     */
    public static String getCheckUsernameUrl() {
        return getApiUrl(CHECK_USERNAME_ENDPOINT);
    }
    
    /**
     * 获取检查邮箱API URL
     */
    public static String getCheckEmailUrl() {
        return getApiUrl(CHECK_EMAIL_ENDPOINT);
    }
    
    /**
     * 获取登出API URL
     */
    public static String getLogoutUrl() {
        return getApiUrl(LOGOUT_ENDPOINT);
    }
    
    /**
     * 获取刷新Token API URL
     */
    public static String getRefreshTokenUrl() {
        return getApiUrl(REFRESH_TOKEN_ENDPOINT);
    }

    /**
     * 获取提交作业 API URL
     */
    public static String getRecordsUrl() {return getApiUrl(ANSWER_RECORDS_ENDPOINT);}


    /**
     * 上传错题
     * @return
     */
    public static  String uploadWrongUrl(){return getApiUrl(UPLOAD_WRONG_ENDPOINT);}

    /**
     * 获取错题列表
     * @return
     */
    public static String getWrongListUrl() {return getApiUrl(WRONNG_LIST_ENDPOINT);}

    /**
     * 提交已完成错题 API URL
     */
    public static String getCompleteWrongUrl() { return getApiUrl(COMPLETE_WRONG_ENDPOINT); }

    //根据根据用户ID查询教师
    public static String getTeacherIdByUserIdUrl(String userId) {
        return getApiUrl(TEACHER_ENDPOINT +userId);
    }
    // 教师端：获取老师管理的班级
    public static String getTeacherClassesUrl(String teacherId) {
        return getApiUrl(TEACHER_CLASSES_ENDPOINT +teacherId);
    }

    // 教师端：获取班级某日总览（使用@RequestParam传参）
    public static String getClassOverviewUrl(int classId, String date) {
        StringBuilder url = new StringBuilder(getApiUrl(CLASS_OVERVIEW_ENDPOINT));
        url.append("?classId=").append(classId);
        if (date != null && !date.isEmpty()) {
            url.append("&time=").append(date);
        }
        return url.toString();
    }

    // 学生：某日成绩详情
    public static String getStudentScoreDetailUrl(int studentId, String date) {
        StringBuilder url = new StringBuilder(getApiUrl(STUDENT_SCORE_DETAIL_ENDPOINT));
        url.append("?studentId=").append(studentId);
        if (date != null && !date.isEmpty()) {
            url.append("&time=").append(date);
        }
        return url.toString();
    }

    /**
     * 获取班级学生列表的URL
     * @param classId 班级ID
     * @return 完整请求URL（匹配后端 /students/class/{classId} 路径）
     */
    public static String getStudentsByClassUrl(Long classId) {
        return BASE_URL + "/students/class/" + classId;
    }

    /**
     * 获取创建学生接口URL
     */
    public static String getCreateStudentUrl() {
        return BASE_URL + "/users/register";
    }

    /**
     * 获取添加学生到班级接口URL
     */
    public static String getAddStudentToClassUrl(long classId) {
        return BASE_URL + "/classes/" + classId + "/add-student";
    }

    /**
     * 获取删除学生的接口URL
     * @param studentId 学生ID
     * @return 完整请求URL（匹配后端 /{id} 路径）
     */
    public static String getDeleteStudentUrl(Long studentId) {
        return BASE_URL + "/students/" + studentId;
    }
} 